#include <QDesktopWidget>
#include "KMessageBox.h"
#include "ui_KMessageBox.h"
int ret;

KMessageBox::KMessageBox(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::KMessageBox)
{
    ret = 0;
    ui->setupUi(this);
    ui->cmdNo->setVisible(false);
    ui->cmdYes->setVisible(false);
    ui->cmdOK->setVisible(false);
}

void KMessageBox::adjustSize()
{
    QDesktopWidget desktop;
    this->move(0,0);
    this->resize(desktop.availableGeometry().width(), desktop.availableGeometry().height());
}

void KMessageBox::ok(const QString &title, const QString &text)
{
    ret = 0;
    adjustSize();
    this->showMaximized();
    ui->cmdNo->setVisible(false);
    ui->cmdYes->setVisible(false);
    ui->cmdOK->setVisible(true);
    this->setWindowTitle(title);
    ui->labText->setText(text);
    this->exec();
}

int KMessageBox::yesno(const QString &title, const QString &text)
{
    ret = 0;
    adjustSize();
    this->showMaximized();
    ui->cmdNo->setVisible(true);
    ui->cmdYes->setVisible(true);
    ui->cmdOK->setVisible(false);
    this->setWindowTitle(title);
    ui->labText->setText(text);
    this->exec();
    return ret;
}

KMessageBox::~KMessageBox()
{
    delete ui;
}

void KMessageBox::on_cmdYes_clicked()
{
    ret = 1;
    this->close();
}

void KMessageBox::on_cmdNo_clicked()
{
    ret = 0;
    this->close();
}

void KMessageBox::on_cmdOK_clicked()
{
    this->close();
}
